package org.hbnu.xiaomi.service;

import org.hbnu.xiaomi.entity.Users;
import org.hbnu.xiaomi.mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//用户数据对象服务
@Service
public class UsersService implements UsersMapper{
    //注入一个用户查询功能
    @Autowired
    UsersMapper usersMapper;

    @Autowired
    public UsersService(UsersMapper usersMapper) {
        this.usersMapper = usersMapper;
    }

    // 查询所有用户
    public List<Users> getAllUsers() {
        return usersMapper.getAllUsers();
    }


    // 根据邮箱查询用户
    public Users getUserByEmail(String email) {
        return usersMapper.getUserByEmail(email);
    }

    //根据id查找用户名称
    @Override
    public String findNicknameById(int user_id) {
        return usersMapper.findNicknameById(user_id);
    }

    // 添加用户
    public void addUser(Users user) {
        usersMapper.addUser(user);
    }

    @Override
    public Users getById(int id) {
        return usersMapper.getById(id);
    }

    // 更新用户信息
    public void updateUser(Users user) {
        usersMapper.updateUser(user);
    }

    // 删除用户
    public void deleteUser(int id) {
        usersMapper.deleteUser(id);
    }


}
